package com.sunwayhorizo.health.hl7.rim;

import java.io.Serializable;
import java.sql.*;
import javax.persistence.*;

import org.jboss.seam.annotations.*;
import com.sunwayhorizo.health.common.*;
import com.sunwayhorizo.health.hl7.common.*;
import com.sunwayhorizo.health.hl7.datatypes.*;
import com.sunwayhorizo.health.hl7.persistent.*;

@Name("ActParticipation")
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@AttributeOverrides({ @AttributeOverride(name = "typeCode", column = @Column(name = "TYPE_CODE")),
        @AttributeOverride(name = "sequenceNum", column = @Column(name = "SEQUENCE_NUM")),
        @AttributeOverride(name = "signatureCodeEtsId", column = @Column(name = "SIGNATURE_CODE_ETS_ID")),
        @AttributeOverride(name = "statusCode", column = @Column(name = "STATUS_CODE"))
})
@DiscriminatorValue("PARTICIPATION")
public class ActParticipation extends RimCoreActPrtcptns implements Serializable
{

    /*
     * public Act Act; public CE AwarenessCode; public CS ContextControlCode;
     * public CD FunctionCode; public CE ModeCode; public BL NegationInd; public
     * ED NoteText; public BL PerformInd; public Role Role; public INT
     * SequenceNumber; public CE SignatureCode; public ED SignatureText; public
     * CE SubstitutionConditionCode; public IVL_TS Time; public CS TypeCode;
     * public CS EncouterNo; //就诊序号/住院号
     */

    /**
	 * 
	 */
    private static final long serialVersionUID = 1L;


    public CS getStatCode() throws Hl7Exception
    {
        String statusCode = this.getStatusCode();
        if (StrUtil.isBlank(statusCode))
        {
            return null;
        }
        return DataTypeUtil.getCS(statusCode);
    }


    public void setStatCode(CS statCode)
    {
        if (null == statCode)
        {
            this.setStatusCode(null);
        }
        this.setStatusCode(statCode.toString());
    }


    public CS getEncouterNo() throws Hl7Exception
    {
        return DataTypeUtil.getCS(this.getEncounterNO());
    }


    public void setEncouterNo(CS encouterNo)
    {
        this.setEncounterNO(encouterNo.code().toString());
    }


    public void setAwarenessCode(CE AwarenessCode)
    {
        this.setAwarenessCodeEtsId(AwarenessCode.code().toString());
    }


    public CE getAwarenessCode() throws Hl7Exception
    {
        return DataTypeUtil.getCE(this.getAwarenessCodeEtsId(), "NullFlavor.NI");
    }


    public void setContextControlCode(CS ContextControlCode)
    {
        this.setContextControlCode(ContextControlCode.code().toString());
    }


    public CS getContextControlCode() throws Hl7Exception
    {
        return DataTypeUtil.getCS(this.getContextControl_Code());
    }


    public void setFunctionCode(CD FunctionCode)
    {
        this.setFunctionCodeEtsId(FunctionCode.code().toString());
    }


    public CD getFunctionCode() throws Hl7Exception
    {
        if (getFunctionCodeEtsId() == null)
        {
            return null;
        }
        return DataTypeUtil.getCE(this.getFunctionCodeEtsId());
    }


    public void setModeCode(CE ModeCode)
    {
        this.setModeCodeEtsId(ModeCode.code().toString());
    }


    public CE getModeCode() throws Hl7Exception
    {
        return DataTypeUtil.getCE(this.getModeCodeEtsId(), "NullFlavor.NI");
    }


    public void setNegationInd(BL NegationInd)
    {
        this.setNegationFlag(NegationInd.toString());
    }


    public BL getNegationInd() throws Hl7Exception
    {
        return DataTypeUtil.getBL(this.getNegationFlag());
    }


    public void setNoteText(ED NoteText)
    {
        RimCoreEds ed = this.getRimCoreEdsNoteTextEdId();
        ed.setEdClob(NoteText.literal().toString().toCharArray());
        ed.setMediaTypeCode(NoteText.mediaType().toString());
        ed.setCharacterSetCode(NoteText.charset().toString());
        ed.setLanguageCode(NoteText.language().toString());
        ed.setCompressionCode(NoteText.compression().toString());
        ed.setRefTelAddressTxt(NoteText.reference().address().toString());
        ed.setRefTelSchemeCode(NoteText.reference().scheme().toString());
        if (null != NoteText.reference().useablePeriod().hull().low())
        {
            ed.setRefTelStartDateTs(new Timestamp(NoteText.reference().useablePeriod().hull().low().toDate().getTime()));
        }
        if (null != NoteText.reference().useablePeriod().hull().high())
        {
            ed.setRefTelEndDateTs(new Timestamp(NoteText.reference().useablePeriod().hull().high().toDate().getTime()));
        }
        ed.setRefTelGtsTxt(NoteText.reference().useablePeriod().literal().toString());
        ed.setEdRefTelUses(NoteText.reference().use().toSet());
        ed.setIntegrityCheckAlgCode(NoteText.integrityCheckAlgorithm().toString());
        if (!NoteText.integrityCheck().isNull().booleanValue())
        {
            ed.setIntegrityCheckTxt(NoteText.integrityCheck().stringValue());
        }
        this.setRimCoreEdsNoteTextEdId(ed);
    }


    public ED getNoteText() throws Hl7Exception
    {
        RimCoreEds ed = this.getRimCoreEdsNoteTextEdId();
        if (null == ed)
        {
            return null;
        }
        return DataTypeUtil.getED(new String(ed.getEdClob()), ed.getEdBlob());
    }


    public void setPerformInd(BL PerformInd)
    {
        this.setPerformFlag(PerformInd.toString());
    }


    public BL getPerformInd() throws Hl7Exception
    {
        return DataTypeUtil.getBL(this.getPerformFlag());
    }


    public Role getRole()
    {
        return (Role) getRoleparticipation();
    }


    public void setSequenceNumber(INT SequenceNumber)
    {
        this.setSequenceNum(SequenceNumber.longValue());
    }


    public INT getSequenceNumber() throws Hl7Exception
    {
        return DataTypeUtil.getINT(this.getSequenceNum());
    }


    public void setSignatureCode(CE SignatureCode)
    {
        this.setSignatureCodeEtsId(SignatureCode.code().toString());
    }


    public CE getSignatureCode() throws Hl7Exception
    {
        if (signatureCodeEtsId == null)
        {
            return null;
        }
        return DataTypeUtil.getCE(getSignatureCodeEtsId());
    }


    public void setSignatureText(ED signatureText)
    {
        // RimCoreEds ed = new RimCoreEds();
        RimCoreEds ed = this.getRimCoreEdsSignatureTextEdId();
        ed.setEdBlob(signatureText.integrityCheck().byteArray()); // 二进制文件
        ed.setEdClob(signatureText.literal().toString().toCharArray()); // 大文本
        ed.setMediaTypeCode(signatureText.mediaType().toString());
        ed.setCharacterSetCode(signatureText.charset().toString());
        ed.setLanguageCode(signatureText.language().toString());
        ed.setCompressionCode(signatureText.compression().toString());
        ed.setRefTelAddressTxt(signatureText.reference().address().toString());
        ed.setRefTelSchemeCode(signatureText.reference().scheme().toString());
        if (null != signatureText.reference().useablePeriod().hull().low())
        {
            ed.setRefTelStartDateTs(new Timestamp(signatureText.reference().useablePeriod().hull().low().toDate().getTime()));
        }
        if (null != signatureText.reference().useablePeriod().hull().high())
        {
            ed.setRefTelEndDateTs(new Timestamp(signatureText.reference().useablePeriod().hull().high().toDate().getTime()));
        }
        ed.setRefTelGtsTxt(signatureText.reference().useablePeriod().literal().toString());
        ed.setEdRefTelUses(signatureText.reference().use().toSet());
        ed.setIntegrityCheckAlgCode(signatureText.integrityCheckAlgorithm().toString());
        if (!signatureText.integrityCheck().isNull().booleanValue())
        {
            ed.setIntegrityCheckTxt(signatureText.integrityCheck().stringValue());
        }
        this.setRimCoreEdsSignatureTextEdId(ed);
    }


    public ED getSignatureText() throws Hl7Exception
    {
        RimCoreEds ed = this.getRimCoreEdsSignatureTextEdId();
        if (null == ed)
        {
            return null;
        }
        return DataTypeUtil.getED(new String(ed.getEdClob()), ed.getEdBlob());
    }


    public void setSubstitutionConditionCode(CE SubstitutionConditionCode)
    {
        this.setSubstitutionConditionEtsId(SubstitutionConditionCode.code().toString());
    }


    public CE getSubstitutionConditionCode() throws Hl7Exception
    {
        return DataTypeUtil.getCE(this.getSubstitutionConditionEtsId(), "NullFlavor.NI");
    }


    public void setTime(IVL_TS Time)
    {
        this.setEffectiveStartDateTs(new Timestamp(Time.low().toDate().getTime()));
        this.setEffectiveEndDateTs(new Timestamp(Time.high().toDate().getTime()));
        this.setEffectiveDateTxt(Time.literal().toString());
        PQ pq = (PQ) Time.width();
        this.setEffectiveDateIvlTxt(pq.value().literal().toString());
        this.setEffectiveDateIvlUomCode(pq.unit().code().toString());
    }


    public IVL_TS getTime() throws Hl7Exception
    {
        return DataTypeUtil.getIVL_TS(this.getEffectiveStartDateTs(), this.getEffectiveEndDateTs());
    }


    public void setTypeCode(CS TypeCode)
    {
        this.setTypeCode(TypeCode.code().toString());
    }


    public CS getTypecode() throws Hl7Exception
    {

        return DataTypeUtil.getCS(this.getTypeCode());
    }


    public void setCreateTime(TS availabilityTime)
    {
        this.setCreateDate(new Timestamp(availabilityTime.toDate().getTime()));
        this.setCreateDateTex(availabilityTime.literal().toString());
    }


    public TS getCreateTime() throws Hl7Exception
    {
        return DataTypeUtil.getTS(new Date(this.getCreateDate().getTime()));
    }

    @Column(name = "AWARENESS_CODE_ETS_ID")
    private String awarenessCodeEtsId;
    @Column(name = "CONTEXT_CONTROL_CODE")
    private String contextControlCode;
    @Column(name = "EFFECTIVE_DATE_IVL_TXT")
    private String effectiveDateIvlTxt;
    @Column(name = "EFFECTIVE_DATE_IVL_UOM_CODE")
    private String effectiveDateIvlUomCode;
    @Column(name = "EFFECTIVE_DATE_TXT")
    private String effectiveDateTxt;
    @Column(name = "EFFECTIVE_END_DATE_TS")
    private Timestamp effectiveEndDateTs;
    @Column(name = "EFFECTIVE_START_DATE_TS")
    private Timestamp effectiveStartDateTs;
    @Column(name = "FUNCTION_CODE_ETS_ID")
    private String functionCodeEtsId;
    @Column(name = "MODE_CODE_ETS_ID")
    private String modeCodeEtsId;
    @Column(name = "NEGATION_FLAG")
    private String negationFlag;
    // @Column(name = "NOTE_TEXT_ED_ID") private Long noteTextEdId;
    @Column(name = "PERFORM_FLAG")
    private String performFlag;

    @Column(name = "REQUEST_ID")
    private Long requestId;

    // @Column(name = "SIGNATURE_TEXT_ED_ID") private Long signatureTextEdId;

    @Column(name = "SUBSTITUTION_CONDITION_ETS_ID")
    private String substitutionConditionEtsId;

    @Column(name = "ENCOUNTER_NO")
    private String encounterNO; // 就诊序号
    @Column(name = "CREATE_DATE")
    private Timestamp createDate; // 操作时间
    @Column(name = "CREATE_DATE_TXT")
    private String createDateTex; // 操作时间Tex


    private String getCreateDateTex()
    {
        return createDateTex;
    }


    private void setCreateDateTex(String createDateTex)
    {
        this.createDateTex = createDateTex;
    }


    private Timestamp getCreateDate()
    {
        return createDate;
    }


    private void setCreateDate(Timestamp createDate)
    {
        this.createDate = createDate;
    }


    private String getAwarenessCodeEtsId()
    {
        return awarenessCodeEtsId;
    }


    private void setAwarenessCodeEtsId(String awarenessCodeEtsId)
    {
        this.awarenessCodeEtsId = awarenessCodeEtsId;
    }


    private String getContextControl_Code()
    {
        return contextControlCode;
    }


    private void setContextControlCode(String contextControlCode)
    {
        this.contextControlCode = contextControlCode;
    }


    private String getEffectiveDateIvlTxt()
    {
        return effectiveDateIvlTxt;
    }


    private void setEffectiveDateIvlTxt(String effectiveDateIvlTxt)
    {
        this.effectiveDateIvlTxt = effectiveDateIvlTxt;
    }


    private String getEffectiveDateIvlUomCode()
    {
        return effectiveDateIvlUomCode;
    }


    private void setEffectiveDateIvlUomCode(String effectiveDateIvlUomCode)
    {
        this.effectiveDateIvlUomCode = effectiveDateIvlUomCode;
    }


    private String getEffectiveDateTxt()
    {
        return effectiveDateTxt;
    }


    private void setEffectiveDateTxt(String effectiveDateTxt)
    {
        this.effectiveDateTxt = effectiveDateTxt;
    }


    private Timestamp getEffectiveEndDateTs()
    {
        return effectiveEndDateTs;
    }


    private void setEffectiveEndDateTs(Timestamp effectiveEndDateTs)
    {
        this.effectiveEndDateTs = effectiveEndDateTs;
    }


    private Timestamp getEffectiveStartDateTs()
    {
        return effectiveStartDateTs;
    }


    private void setEffectiveStartDateTs(Timestamp effectiveStartDateTs)
    {
        this.effectiveStartDateTs = effectiveStartDateTs;
    }


    private String getFunctionCodeEtsId()
    {
        return functionCodeEtsId;
    }


    private void setFunctionCodeEtsId(String functionCodeEtsId)
    {
        this.functionCodeEtsId = functionCodeEtsId;
    }


    private String getModeCodeEtsId()
    {
        return modeCodeEtsId;
    }


    private void setModeCodeEtsId(String modeCodeEtsId)
    {
        this.modeCodeEtsId = modeCodeEtsId;
    }


    private String getNegationFlag()
    {
        return negationFlag;
    }


    private void setNegationFlag(String negationFlag)
    {
        this.negationFlag = negationFlag;
    }


    private String getPerformFlag()
    {
        return performFlag;
    }


    private void setPerformFlag(String performFlag)
    {
        this.performFlag = performFlag;
    }


    private String getSignatureCodeEtsId()
    {
        return signatureCodeEtsId;
    }


    private void setSignatureCodeEtsId(String signatureCodeEtsId)
    {
        this.signatureCodeEtsId = signatureCodeEtsId;
    }


    private String getSubstitutionConditionEtsId()
    {
        return substitutionConditionEtsId;
    }


    private void setSubstitutionConditionEtsId(String substitutionConditionEtsId)
    {
        this.substitutionConditionEtsId = substitutionConditionEtsId;
    }


    private String getEncounterNO()
    {
        return encounterNO;
    }


    private void setEncounterNO(String encounterNO)
    {
        this.encounterNO = encounterNO;
    }

}
